package cn.tedu._05mvcboot04.base.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * @author Justin Parker
 * @author 2024/8/18 17:39
 * @version 1.0
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    @ApiModelProperty(value = "状态码")
    private Integer status;
    @ApiModelProperty(value = "提示信息")
    private String message;
    @ApiModelProperty(value = "响应数据")
    private Object data;


    public JsonResult(StatusCode statusCode){
        this.status = statusCode.getStatus();
        this.message = statusCode.getMessage();
    }
    //构造方法
    public JsonResult(StatusCode statusCode ,Object data){
        this.status = statusCode.getStatus();
        this.message = statusCode.getMessage();
        this.data = data;
    }



    public static JsonResult ok(Object data){
        return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }

    public static JsonResult ok(){
        return ok(null);
    }



    public static JsonResult fail(Object data){
        return new JsonResult(StatusCode.OPERATION_FAILED,data);
    }
    public static JsonResult fail(){
        return fail(null);
    }
}
